<?php

namespace Xin\ThinkPHP\Cache;

use think\cache\driver\Memcached as MemcachedDriver;
use Xin\Lock\Contracts\LockProvider;
use Xin\Lock\MemcachedLock;

class Memcached extends MemcachedDriver implements LockProvider
{

    /**
     * @inheritDoc
     * @noinspection PhpParamsInspection
     */
    public function lock($name, $seconds = 0, $owner = null)
    {
        return new MemcachedLock($this->handler, $this->getCacheKey($name), $seconds, $owner);
    }

    /**
     * @inheritDoc
     */
    public function restoreLock($name, $owner)
    {
        return $this->lock($name, 0, $owner);
    }

}
